import fetch from '@/utils/fetch'
import {getUserId} from '@/utils/token'

export function apiGetAccountList(listQuery) {
  listQuery.id = getUserId()
  return fetch({
    url: '/api/v1/userManage/list',
    method: 'get',
    params: listQuery
  })
}

export function apiGetUserRole(listQuery) {
  return fetch({
    url: '/api/v1/userManage/userRole',
    method: 'get',
    params: listQuery
  })
}

export function apiGetRoleInfo(listQuery) {
  return fetch({
    url: '/api/v1/userManage/roleInfo',
    method: 'get',
    params: listQuery
  })
}

export function apiGetAccountById(userId) {
  return fetch({
    url: '/api/v1/user',
    method: 'get',
    params: {
      id: userId
    }
  })
}

export function apiGetUserById(userId) {
  return fetch({
    url: '/api/v1/user/update',
    method: 'get',
    params: {
      id: userId
    }
  })
}

export function apiAddAccount(accountDto) {
  return fetch({
    url: '/api/v1/userManage',
    method: 'post',
    data: accountDto
  })
}

export function apiGetTypeList(listQuery) {
  return fetch({
    url: '/api/v1/userManage/list',
    method: 'get',
    params: listQuery
  })
}

// 用户分配角色
export function apiRoleAccount(data) {
  return fetch({
    url: '/api/v1/userManage/role',
    method: 'post',
    data: data
  })
}

export function apiUpdAccount(accountDto) {
  return fetch({
    url: '/api/v1/home/login',
    method: 'put',
    data: accountDto
  })
}

export function apiUpdUser(accountDto) {
  return fetch({
    url: '/api/v1/user',
    method: 'put',
    data: accountDto
  })
}

export function apiDelAccount(listQuery) {
  return fetch({
    url: '/api/v1/userManage',
    method: 'delete',
    params: listQuery
  })
}

export function apiEnableAccount(userIdDto) {
  return fetch({
    url: '/api/v1/userManage/enable',
    method: 'post',
    data: userIdDto
  })
}

export function apiDisableAccount(userIdDto) {
  return fetch({
    url: '/api/v1/userManage/disable',
    method: 'post',
    data: userIdDto
  })
}

export function apiGetRoleIdList(listQuery) {
  return fetch({
    url: '/api/v1/role/roleIdList',
    method: 'GET',
    params: listQuery
  })
}

export function apiExport (listQuery) {
  return fetch({
    url: '/api/v1/userManage/export',
    method: 'post',
    data: listQuery,
    responseType: 'arraybuffer'
  })
}
